//
//  HomeSegTitleCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/8/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "HomeSegTitleCell.h"

//static CGFloat CellScaleValueMax = 1.0f;

@interface HomeSegTitleCell ()

@property (nonatomic, assign) BOOL isSelected;


@end

@implementation HomeSegTitleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

//设置布局
- (void)layoutSubviews {
    [super layoutSubviews];

//    if (self.isSelected) {
//        self.transform = CGAffineTransformMakeScale(CellScaleValueMax, CellScaleValueMax);
//    }else {
//        self.transform = CGAffineTransformIdentity;
//    }
}

//通过此父类方法配置cell是否被选中
- (void)configCellOfSelected:(BOOL)selected {
    [super configCellOfSelected:selected];
    
    self.isSelected = selected;
    
    UIColor *color = selected ? self.config.titleSelectedColor : self.config.titleNormalColor;
    
    self.mainTitle.textColor = color;
    
    if (selected) {
        
        self.bgImage.hidden = NO;
//        self.subTitle.textColor = [UIColor whiteColor];
//        self.subTitle.layer.backgroundColor = color.CGColor;
//        self.subTitle.layer.cornerRadius = 8;
        
//        self.transform = CGAffineTransformMakeScale(CellScaleValueMax, CellScaleValueMax);
    }else {
        
        self.bgImage.hidden = YES;

//        self.subTitle.textColor = color;
//        self.subTitle.layer.backgroundColor = [UIColor whiteColor].CGColor;
//        self.subTitle.layer.cornerRadius = 8;
        
//        self.transform = CGAffineTransformIdentity;
    }
}

//通过此父类方法配置cell动画 progress0~1
- (void)showAnimationOfProgress:(CGFloat)progress type:(XLPageTitleCellAnimationType)type {
    [super showAnimationOfProgress:progress type:type];
    //动画包括颜色渐变 缩放
//    if (type == XLPageTitleCellAnimationTypeSelected) {
//        //第一步 颜色渐变
//        UIColor *newColor = [XLPageViewControllerUtil colorTransformFrom:self.config.titleSelectedColor to:self.config.titleNormalColor progress:progress];
//        [self updateSubviewsColor:newColor];
//        //第二步 缩放 逐渐变小
//        CGFloat scale = (1 - progress)*(CellScaleValueMax - 1);
//        self.transform = CGAffineTransformMakeScale(1 + scale, 1 + scale);
//    }else if (type == XLPageTitleCellAnimationTypeWillSelected){
//        //第一步 颜色渐变
//        UIColor *newColor = [XLPageViewControllerUtil colorTransformFrom:self.config.titleNormalColor to:self.config.titleSelectedColor progress:progress];
//        [self updateSubviewsColor:newColor];
//        
//        //第二步 缩放 逐渐变大
//        CGFloat scale = progress*(CellScaleValueMax - 1);
//        self.transform = CGAffineTransformMakeScale(1 + scale, 1 + scale);
//    }
}

- (void)updateSubviewsColor:(UIColor *)color {
    self.mainTitle.textColor = color;
//    self.subTitle.textColor = color;
}

@end
